package com.sgb.kjwl.view.ui.activity.self.authentication;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityUserAuthDetailBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.manage.WebsiteInfoEntity;
import com.sgb.kjwl.model.entity.user.AuthDetailEntity;
import com.sgb.kjwl.viewmodel.self.UserAuthDetailModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.ClickUtils;

import javax.inject.Inject;

/**
 * 实名认证详情
 */
public class UserAuthDetailActivity extends AppActivity {
    private ActivityUserAuthDetailBinding binding;
    String userNo;

    private AuthDetailEntity mEntity;

    @Inject
    UserAuthDetailModel viewModel;

    private static final int REQUEST_CODE = 100100;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder().appComponent(appComponent).selfModule(new SelfModule(this)).build().inject(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    //设置状态栏为暗
    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void initView() {
        //双向绑定Activity和View
        binding = DataBindingUtil.setContentView(UserAuthDetailActivity.this, R.layout.activity_user_auth_detail);
        binding.nsView.setVisibility(View.INVISIBLE);
        userNo = getIntent().getStringExtra("userNo");
        viewModel.getUserInfo(userNo);
        binding.include.titleView.setText("认证详情");
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.tvAgainAuth.setOnClickListener(v -> {
                if (!ClickUtils.isDoubleClick()){
                    CertificationActivity.startActivityResult(this, "1", mEntity, REQUEST_CODE);
                    finish();
                }
        });
    }

    public void showDetail(AuthDetailEntity entity) {
        mEntity = entity;
        binding.nsView.setVisibility(View.VISIBLE);
        binding.setEntity(entity);
        switch (entity.getStatus()){
            case 1:
                binding.logo.setImageResource(R.mipmap.authen_ing);
                binding.text.setText("审核中");
                binding.tvAgainAuth.setVisibility(View.GONE);
                break;
            case 2:
                binding.logo.setImageResource(R.mipmap.auth_success);
                binding.text.setText("认证成功");
                binding.tvAgainAuth.setVisibility(View.GONE);
                break;
            case 3:
                binding.logo.setImageResource(R.mipmap.authen_fail);
                binding.text.setText("审核失败");
                binding.tvAgainAuth.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
            if (data != null && data.getSerializableExtra(CertificationActivity.KEY_DATA) != null){
                AuthDetailEntity entity = (AuthDetailEntity) data.getSerializableExtra(CertificationActivity.KEY_DATA);
                showDetail(entity);
            }
        }
    }
}
